#include "ButtonWindow.h"
#include "WndProcPicker.h"


namespace Zaf {
namespace Mwl {


const wchar_t* const ButtonWindow::ClassName = L"BUTTON";
__Internal::WndProcPicker ButtonWindow::ButtonWndProc(ButtonWindow::ClassName);



ButtonWindow::ButtonWindow() {
	CommonConstructor();
}



ButtonWindow::ButtonWindow(WORD id) : ControlWindow(id) {
	CommonConstructor();
}



ButtonWindow::~ButtonWindow() {

}



HWND ButtonWindow::CreateConcreteWindow() {

	unsigned int x;
	unsigned int y;
	GetPosition(x, y);

	unsigned int width;
	unsigned int height;
	GetSize(width, height);

	return CreateWindowEx(
		GetExStyle(),
		ClassName,
		GetText().c_str(),
		GetStyle(),
		x,
		y,
		width,
		height,
		GetParentOrOwner(),
		(HMENU)GetID(),
		GetModuleHandle(NULL),
		0
	);
}



void ButtonWindow::CommonConstructor() {

}



LRESULT ButtonWindow::OnCommand(const WndMsg& msg) {

	if (msg.WParamHigh == BN_CLICKED) {

		ClickedEventArgs args;
		args.Sender = this;

		ClickedEvent.Invoke(args);
	}

	return 0;
}



DWORD ButtonWindow::GetButtonType() const {
	return GetStyle() & BS_TYPEMASK;
}


void ButtonWindow::SetButtonType(DWORD type) {
	SetStyle(GetStyle() & ~BS_TYPEMASK | type);
}


LRESULT ButtonWindow::DefWndProc(const WndMsg& msg) {
	return ButtonWndProc(msg.Hwnd, msg.Message, msg.WParam, msg.LParam);
}

}
}